<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台大布局 - Layui</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/layui/layui.js"></script>
    <script src="/static/myJS/custom.js"></script>
    <script src="/static/moment/moment.min.js"></script>
    <script src="/static/JQuery/jquery-3.3.1.min.js"></script>
</head>
<body class="layui-layout-body" style="padding: 10px">

<form class="layui-form" action="" lay-filter="recordEdit">
    <input type="hidden" id="recordid" name="recordid" />
    <input type="hidden" id="fkgoodsid" name="fkgoodsid" />
    <input type="hidden" id="fkorderid" name="fkorderid" />
    <input type="hidden" id="recordnum" name="recordnum" />
    <input type="hidden" id="recordprice" name="recordprice" />
    <input type="hidden" id="star" name="star" />

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">评分</label>
            <div class="layui-input-inline">
                <div><div id="test4"></div></div>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">评价</label>
            <div class="layui-input-inline">
                <input type="text" name="remark" class="layui-input">
            </div>
        </div>
    </div>



    <div class="layui-col-md-offset5">
        <div class="layui-input-block">
            <button class="layui-btn" type="button" lay-submit lay-filter="recordSubmit">立即提交</button>
        </div>
    </div>
</form>

</body>

</html>

<script>

    var star = 0;
    layui.use(['form', 'layedit', 'laydate', 'layer', 'rate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,rate = layui.rate
            ,laydate = layui.laydate;
        
        rate.render({
            elem: '#test4'
            ,value: 0
            ,half: true
            ,text: true
            ,choose: function(value){
                star = value;
                $("#star").val(value);
            }
        });

        if(localStorage.recordid){
            $.ajax({
                url:"/restful/find",
                type:"POST",
                data:JSON.stringify({
                    firstTable:"records",
                    wheres:[{field:"records.recordid",value:localStorage.recordid}]
                }),
                contentType: "application/json;charset=utf-8",
                dataType : "json",
                async:false,
                success : function(result) {
                    var data = result.data[0];
                    //表单input初始赋值
                    form.val('recordEdit', data);
                },
                error:function(result){
                    layer.alert(result.msg);
                }
            });
        }
        
        form.on('submit(recordSubmit)', function(data){
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            data.field['remarktime'] = moment().format('YYYY-MM-DD HH:mm:ss');
            $.ajax({
                url:"/order/remark",
                type:"POST",
                data:JSON.stringify(data.field),
                contentType: "application/json;charset=utf-8",
                dataType : "json",
                async: false,
                success : function(result) {
                    if(result.code === 0){
                        parent.layer.msg(result.msg, {icon : 1});
                    }else{
                        parent.layer.msg(result.msg, {icon : 5});
                    }
                },
                error:function(result){
                    parent.layer.msg(result.msg, {icon : 5});
                }
            });
            parent.layer.close(index);
            return false;
        });

    });


</script>
